package com.pineapple.module.core.login.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.pineapple.module.core.login.domain.LoginCriteria;
import com.pineapple.module.core.login.domain.User;

public class LoginDAO {

	protected User login(LoginCriteria criteria,Connection conn) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT * FROM user ");
		sql.append("WHERE user_name ='"+criteria.getUsername()+"' ");
		sql.append("AND user_password='"+criteria.getPassword()+"' ");
		User user = new User();
		try(Statement stmt = conn.createStatement()){
			  ResultSet rs = stmt.executeQuery(sql.toString());

		        if(rs.next()) {
		        	user.setUserId(rs.getString("user_id"));
		        	user.setUserName(rs.getString("user_name"));
		        	user.setName(rs.getString("user_fname"));
		        	user.setSurName(rs.getString("user_lname"));
		        	user.setPassword(rs.getString("user_password"));
		        	user.setAddress(rs.getString("user_address"));
		        	user.setPhone(rs.getString("user_landlines"));
		        	user.setMobile(rs.getString("user_moblie"));
		        	user.setPeopleId(rs.getString("user_idcard"));
		        }


		}catch(Exception ex){
			ex.printStackTrace();
		}
		return user;
	}
}
